package com.xieyong.leetcode;

public class Leetcode2929 {
    public static void main(String[] args) {
        Leetcode2929 leetcode = new Leetcode2929();
        int n = 5,limit = 2;
        long l = leetcode.distributeCandies(n, limit);
        System.out.println(l);
    }


    public long distributeCandies(int n, int limit) {
        long res  = 0;
        for(int i = 0; i <= Math.min(limit,n); i++) {
            int left = n - i;
            if(left > 2 * limit) continue;
            if(left <= limit) res += left + 1;
            else res += (limit - (left - limit)) + 1;
        }
        return res;
    }
}
